import axios from 'axios'

/**
 * 用户注册
 * @param data
 * @returns {Promise<Promise<axios.AxiosResponse<any>> | *>}
 */
export const register = async (data) => {
  return axios({
    method: 'post',
    url: '/dataset/user/register',
    data
  })
}

/**
 * 用户登录
 * @param data
 * @returns {Promise<Promise<axios.AxiosResponse<any>> | *>}
 */
export const login = async (data) => {
  return axios({
    method: 'post',
    url: '/dataset/user/login',
    data
  })
}

/**
 * 分页查询原始数据集
 * @param params
 * @returns {Promise<Promise<AxiosResponse<any>> | *>}
 */
export const queryOriginDataset = async (params) => {
  return await axios({
    method: 'get',
    url: '/dataset/origin_dataset/query',
    params
  })
}

/**
 * 编辑原始数据集
 * @param data
 * @returns {Promise<Promise<AxiosResponse<any>> | *>}
 */
export const editOriginDataset = async (data, username) => {
  return await axios({
    method: 'post',
    url: '/dataset/origin_dataset/edit?username=' + username,
    data
  })
}

/**
 * 根据id删除原始数据集
 * @returns {Promise<Promise<AxiosResponse<any>> | *>}
 * @param id
 * @param username
 */
export const deleteOriginDataset = async (id, username) => {
  return await axios({
    url: '/dataset/origin_dataset/delete?id=' + id + "&username=" + username,
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

/**
 * 校验文本是否为JSON格式
 * @param data
 * @returns {Promise<Promise<axios.AxiosResponse<any>> | *>}
 */
export const validateJsonStr = async (data) => {
  return await axios({
    url: '/dataset/validate/json',
    method: 'post',
    data
  })
}

/**
 * 分页查询训练数据集
 * @param params
 * @returns {Promise<Promise<axios.AxiosResponse<any>> | *>}
 */
export const queryTrain = async (params) => {
  return await axios({
    url: '/dataset/train_dataset/query',
    method: 'get',
    params
  })
}

/**
 * 修改训练数据集
 * @param data
 * @returns {Promise<Promise<axios.AxiosResponse<any>> | *>}
 */
export const editTrain = async (data) => {
  return await axios({
    url: '/dataset/train_dataset/edit',
    method: 'post',
    data
  })
}

/**
 * 根据id删除训练数据集
 * @param id
 * @param username
 * @returns {Promise<Promise<axios.AxiosResponse<any>> | *>}
 */
export const deleteTrainDataset = async (id, username) => {
  return await axios({
    url: '/dataset/train_dataset/delete?id=' + id + "&username=" + username,
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}


/**
 * 上传文件到原始数据集
 * @param formData
 * @returns {Promise<Promise<axios.AxiosResponse<any>> | *>}
 */
export const uploadOriginDataset = async (formData) => {
  return await axios({
    url: '/dataset/origin_dataset/upload',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}

/**
 * 上传数据到训练数据集
 * @param formData
 * @returns {Promise<Promise<axios.AxiosResponse<any>> | *>}
 */
export const uploadTrainDataset = async (formData) => {
  return await axios({
    url: '/dataset/train_dataset/upload',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}
